<!--!
This file is a part of MediaDrop (https://www.mediadrop.video),
Copyright 2009-2018 MediaDrop contributors
For the exact contribution history, see the git revision log.
The source code contained in this file is licensed under the GPLv3 or
(at your option) any later version.
See LICENSE.txt in the main project directory, for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:i18n="http://genshi.edgewall.org/i18n"
      xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="/admin/settings/master.html" />
<head>
	<title>Categories</title>
	<script src="${h.url_for('/scripts/third-party/squeezebox-1.1-rc4-yui-compressed.js')}" type="text/javascript"></script>
	<link href="${h.url_for('/admin/styles/squeezebox.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/forms.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/categories.css')}" media="screen" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${h.url_for('/admin/scripts/forms.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/modals.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/confirm.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/tablemgrs.js')}"></script>
	<script type="text/javascript">
		window.addEvent('domready', function(){
			var cattbl = new CategoryTable('category-table', {
				addButton: 'add-category-btn',
				addModal: 'add-category-box',
				editModal: 'edit-category-box',
				deleteModal: 'delete-category-box',
				prefix: 'cat-'
			});
			var bulkDeleteCat = new BulkDelete(cattbl, {
				saveUrl: '${h.url_for(controller='/admin/categories', action='bulk', type='delete')}',
				confirmMgr: {
					header: '${_('Confirm Delete')}',
					msg: function(num){ return '${_('Are you sure you want to delete these %(num)s items?') % dict(num="'+num+'")}'; },
					confirmButtonText: '${_('Delete')}',
					cancelButtonText: '${_('Cancel')}',
				}
			});
			$$('bulk-delete-cat').addEvent('click', bulkDeleteCat.onClick.bind(bulkDeleteCat));
		});
	</script>
</head>
<body class="menu-cattags-on">
	<div class="box">
		<div class="box-head">
			<h1>Categories</h1>
			<div class="f-rgt">
				<a id="add-category-btn" href="${h.url_for(action='edit', id='new')}" class="btn inline btn-add-category f-lft"><span>Add Category</span></a>
				<button id="bulk-delete-cat" class="btn inline btn-add-tag f-lft" style="margin-left:10px"><span>Bulk Delete</span></button>
			</div>
			<!--!<span class="box-head-sec">${h.doc_link('admin/settings', 'categories')}</span>-->
		</div>
		<table cellpadding="0" cellspacing="0" id="category-table">
			<thead>
				<tr>
					<th id="h-bulk" style="width:20px"><input type="checkbox" class="bulk-toggle" /></th>
					<th id="h-name">Name</th>
					<th id="h-media_count" style="width:58px" class="center">Media</th>
					<th id="h-btns"></th>
				</tr>
			</thead>
			<tbody>
				<py:def function="category_rows(cats, depth=0)" py:for="i, cat in enumerate(cats)">
					<tr py:replace="category_row_form(category=cat, depth=depth, first_child=i == 0)" />
					<tr py:if="cat.children" py:replace="category_rows(cat.children, depth + 1)" />
				</py:def>
				${category_rows(categories)}
			</tbody>
		</table>
	</div>

	<div id="add-category-box" class="box hidden">
		<h1 class="box-head">Add Category</h1>
		${category_form(action=h.url_for(action='save', id='new'))}
	</div>
	<div id="edit-category-box" class="box hidden">
		<h1 class="box-head">Edit Category</h1>
		${category_form()}
	</div>
	<div id="delete-category-box" class="box hidden">
		<h1 class="box-head">Delete Category</h1>
		<form>
			<input py:for="field in ('name', 'slug', 'parent_id')" type="hidden" name="${field}" value="" />
			<p class="box-content" i18n:msg="strong">Are you sure you want to delete this category <strong>and ALL of its children</strong>?</p>
			<div class="box-foot">
				<button type="reset" name="cancel" class="btn f-lft"><span>Cancel</span></button>
				<button type="submit" name="delete" class="btn red f-rgt"><span>Delete</span></button>
			</div>
		</form>
	</div>

</body>
</html>
